/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sistemas.sisgear.dao;

import com.sistemas.sisgear.entidades.Opcion;
import com.sistemas.sisgear.entidades.Usuario;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

/**
 *
 * @author Jorge
 */
@Stateless
public class UsuarioFacade extends AbstractFacade<Usuario> {
    @PersistenceContext(unitName = "com.mycompany_Pruebamaven_war_1.0-SNAPSHOTPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public UsuarioFacade() {
        super(Usuario.class);
    }
    
    public boolean loginControl(String username, String password){

        try{
            TypedQuery<Opcion> query = em.createNamedQuery("Usuario.loginControl", Opcion.class);
            query.setParameter("nick", username);
            query.setParameter("pass", password);

            return query.getResultList().size() > 0;
        } catch (Exception e){
            return false;
        }
    }
    
}
